//
//  ChangeNickViewController.m
//  NewProject
//
//  Created by admin on 2017/6/20.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "ChangeNickViewController.h"

@interface ChangeNickViewController ()
@property(nonatomic,strong) UIButton *rightBarButton;
@property(nonatomic,strong) UIButton *clearButton;
@property(nonatomic,strong) UILabel *tipLabel;

@end

@implementation ChangeNickViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"修改昵称";
    self.view.backgroundColor = RGB0X(0xF8F9F6);
    
    _rightBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBarButton.frame = CGRectMake(5/WIDTH_6_SCALE, 0, 50, 50);
    [_rightBarButton setTitle:@"确定" forState:UIControlStateNormal];
    [_rightBarButton setTitleColor:RGB0X(0xFEDB18) forState:UIControlStateNormal];
    _rightBarButton.titleLabel.font = FONT(13);
//    [_rightBarButton setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 24/WIDTH_6_SCALE)];
    [_rightBarButton addTarget:self action:@selector(rightAction) forControlEvents: UIControlEventTouchUpInside];
    UIBarButtonItem *back=[[UIBarButtonItem alloc]initWithCustomView:_rightBarButton];
//    UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
//    nagetiveSpacer.width = -7;//这个值可以根据自己需要自己调整
    self.navigationItem.rightBarButtonItems=@[back];
    
    _nickTextField = [[UITextField alloc]init];
    _nickTextField.placeholder = @"输入名称";
    _nickTextField.backgroundColor = [UIColor whiteColor];
    _nickTextField.font = FONT(13);
    [_nickTextField setValue:[NSNumber numberWithInteger:10/WIDTH_6_SCALE] forKey:@"paddingTop"];
    [_nickTextField setValue:[NSNumber numberWithInteger:15/WIDTH_6_SCALE] forKey:@"paddingLeft"];
    [self.view addSubview:_nickTextField];

//    _clearButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [_clearButton setImage:@"" forState:UIControlStateNormal];
    
    _tipLabel = [[UILabel alloc]init];
    _tipLabel.text = @"2-16个字符。只能输入中英文或数字";
    _tipLabel.textColor = RGB0X(0x9E9E9E);
    _tipLabel.font = FONT(10);
    [self.view addSubview:_tipLabel];
    
    [_nickTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(self.view.mas_top).offset(8/WIDTH_6_SCALE);
        make.right.equalTo(self.view.mas_right);
        make.height.mas_equalTo(40/WIDTH_6_SCALE);
    }];
    
    [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15/WIDTH_6_SCALE);
        make.top.equalTo(self.nickTextField.mas_bottom).offset(5/WIDTH_6_SCALE);
    }];
    // Do any additional setup after loading the view.
}

- (void)rightAction{
    [self.view endEditing:YES];
    if (self.delegate) {
        if ([self.delegate respondsToSelector:@selector(callBackAfterEdit:)]) {
            [self.delegate callBackAfterEdit:_nickTextField.text];
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
